#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDomDocument>
#include <QDomElement>
#include <QDomNode>
#include <QDomProcessingInstruction>
#include <QList>
#include <QString>
#include <QStringList>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QMessageBox>
#include <QEvent>
#include <QMouseEvent>
#include <QProcess>
#include <iostream>
#include <string>
#include <QDebug>
#include <QMap>
using namespace std;
//需要解析的xml数据类型
class XMLFile;
class XMLMsg;
namespace Ui {
class Widget;
}
typedef QList<XMLFile> XMLFileList;
typedef QList<XMLMsg> MsgList;
class XMLMsg
{
public:
    bool      m_needMAC;
    QString   m_strId;
    XMLFileList m_reqFieldList;
    XMLFileList m_respFieldList;
    XMLMsg(const QString& strId = "",
            const bool needMAC = false ):
            m_strId( strId ),
            m_needMAC( needMAC ){}
    bool operator==(const XMLMsg& it)
    {
        return (m_strId == it.m_strId);
    }
};

class XMLFile
{
public:
    QString m_strFlag;
    QString m_strId;
    QString m_tagName;
    QString m_strValue;
    QString m_strRequestPath;
    QString m_strResponsePath;
    QString m_strRemark;
    XMLFile(const QString &strFlag ="",
            const QString &strId  = "",
            const QString &tagName = "",
            const QString &strVal = "",
            const QString &strRequestPath = "",
            const QString &strResponsePath = "",
            const QString &strRemark =""):
        m_strFlag( strFlag),
        m_strId( strId ),
        m_tagName( tagName ),
        m_strValue( strVal ),
        m_strRequestPath( strRequestPath ),
        m_strResponsePath( strResponsePath ),
        m_strRemark ( strRemark ){}
    bool operator ==(const XMLFile& XMLID)
    {
        return (m_strId == XMLID.m_strId);
    }

};
typedef struct msgField{
    QString m_strTagName;
    QString m_strRequestPath;
    QString m_strResponsePath;
    QString m_strValue;
    QString m_strRemark;
    msgField(const QString &tagName ="",
             const QString &strRequestPath ="",
             const QString &strResponsePath ="",
             const QString &strValue ="",
             const QString &strRemark =""
            ):m_strTagName(tagName),
        m_strRequestPath(strRequestPath),
        m_strResponsePath(strResponsePath),
        m_strValue(strValue),
        m_strRemark(strRemark)
    {}


}FieldGather;

typedef  QList<FieldGather> FieldGatherList;
typedef  QMap<QString,QString> FieldMap;
class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
    void initApp();
    void bindConnect();
    void installAppFilter();
    void checkTargetSaveFile();
    void ReadMsg(QString &filePath);
    QDomElement& ParseNode(const QDomElement &root,int arg);
    void createXML(QString &filePath);
    void appendXML(QString &filePath,XMLFileList &fileList,QString &msgID,QString &msgName,QString &Mac);
    void CreateSecondNode(QDomDocument &doc,QDomElement &root,XMLFileList &fileList);
    //事件过滤器
    bool eventFilter(QObject *obj, QEvent *e);

    //数字大小比较
    int fillBlankSpace(int arg1,int arg2);
    int CompareThreeNum(int arg1,int arg2,int m_arg3 = 0);
signals:
    void dblMouseButtonSignal(QString arg);

private slots:
    void on_pushButton_clicked();
    //void on_dblMouseButton_clicked();


    void on_buttonFile_clicked();

    void on_buttonTransMsg_clicked();

    void on_buttonTransdef_clicked();

private:
    Ui::Widget *ui;
    XMLFileList m_XMLList;
    XMLFile m_XMLRoot;
    QString m_AppID;
    QString m_msgID;
    QString m_MAC;

    FieldGather m_Field;
    FieldGatherList m_FieldGatherList;
    int m_resNum;
    int m_resRemarkNum;
    int m_respNum;
    int m_respRemarkNum;
    int m_resTagLenMax;
    int m_respTagLenMax;
    FieldMap m_FieldMap;
    int m_TrandataDefLen;
    QString m_tempDir;

};

#endif // WIDGET_H
